package cn.jk.service;

import cn.jk.config.MyApplicationEvent;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;


/**
 * 实现ApplicationEventPublisherAware接口
 * 可以发布事件
 */
@Service
public class ListenService implements ApplicationEventPublisherAware, ApplicationContextAware {

	ApplicationEventPublisher applicationEventPublisher;

	ApplicationContext context;

	public void test(){
		applicationEventPublisher.publishEvent(new MyApplicationEvent<Integer>(context));
		System.out.println("test");
	}



	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
		this.applicationEventPublisher = applicationEventPublisher;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.context = applicationContext;
	}
}
